import http from '@/util/http.js'

const moduel = {
  namespaced: true, // 开启命名空间
  state: {
    vuex_cinemaList: []
  },
  mutations: {
    vuex_setCinemaList (state, data) {
      state.vuex_cinemaList = data
    },
    clear_vuex_list (state) {
      state.vuex_cinemaList = []
    }
  },
  actions: {
    // 这里的cityId 是 dispatch传过来的城市id
    getCinemaList (store, cityId) {
      return http({
        method: 'get',
        url: `/gateway?cityId=${cityId}&ticketFlag=1&k=5681501`,
        headers: {
          'X-Host': 'mall.film-ticket.cinema.list'
        }
      }).then(res => {
        // console.log(res.data)
        // 这里只是到actions中，要继续提交到mutations中
        store.commit('vuex_setCinemaList', res.data.data.cinemas)
      })
    }
  }
}

export default moduel
